package com.yuexunit.mobilenurse.module.SignInput.ui;

import android.content.Intent;
import android.os.Bundle;
import android.widget.ListView;

import com.yuexunit.mobilenurse.R;
import com.yuexunit.mobilenurse.base.AppContext;
import com.yuexunit.mobilenurse.module.SignInput.adapter.AddTypeAdapter;
import com.yuexunit.mobilenurse.module.SignInput.bean.SignsInput_Data;
import com.yuexunit.mobilenurse.module.SignInput.model.impl.SignModel;
import com.yuexunit.mobilenurse.module.SignInput.presenter.impl.SignPresenter;
import com.yuexunit.mobilenurse.module.SignInput.ui.view.IAddSignType;

import org.kymjs.kjframe.KJActivity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by sslcjy on 16/1/27.
 */
public class Act_AddType extends KJActivity implements IAddSignType {

    @Bind(R.id.add_type)
    ListView addList;

    public ArrayList<SignsInput_Data> types = new ArrayList<SignsInput_Data>();
    public AddTypeAdapter addTypeAdapter;
    private SignPresenter presenter;

    //记录Log
    private final Logger log = LoggerFactory.getLogger(Act_AddType.class);

    @Override
    public void setRootView() {
        setContentView(R.layout.act_addtype);
        ButterKnife.bind(this);
    }

    @Override
    public void initData() {
        super.initData();
        presenter = new SignPresenter(new SignModel(),this);
        initAllTypes();
    }

    @Override
    public void initWidget() {
        super.initWidget();
    }

    @OnClick(R.id.left_text)
    public void out(){
        finish();
    }

    @OnClick(R.id.right_text)
    public void complete(){
        AddTypeForBase();
    }

    @Override
    public void showAllType(ArrayList<SignsInput_Data> baselist) {
        addTypeAdapter = new AddTypeAdapter(addList, baselist, R.layout.item_add_type);
        addList.setAdapter(addTypeAdapter);
    }

    public void AddTypeForBase() {
        Bundle bundle = new Bundle();
        ArrayList lists = new ArrayList();
        Intent intent = new Intent();
        if(addTypeAdapter != null){
            ArrayList<SignsInput_Data> addtypes = addTypeAdapter.getArrayList();
            lists.add(addtypes);
            bundle.putParcelableArrayList("addtypelist", lists);
            intent.putExtras(bundle);
        }
        setResult(RESULT_OK, intent);
        finish();
    }

    private void initAllTypes() {
        types = ((AppContext) getApplication()).getAllTypes();
        if (types.size() > 0) {
            addTypeAdapter = new AddTypeAdapter(addList, types, R.layout.item_add_type);
            addList.setAdapter(addTypeAdapter);
        } else {
            presenter.showAllTypes("a1");
        }
    }
}
